﻿using Microsoft.AspNetCore.Mvc;
using ZingBlog.Domain.Entities;
using ZingBlog.Dto;
using ZingBlog.IService;
using ZingBlog.Web.Areas.Admin.Controllers;

namespace ZingBlog.Web.Areas.Blog.Controllers
{
    [Area("Blog")]
    public class ArticleClassController : BaseController
    {
        public IArticleClassService articleClassService { get; set; }
        // GET: Blog/ArticleClass
        public override ActionResult Index(int? id)
        {
            base.Index(id);
            return View();
        }
        /// <summary>
        /// 加载数据列表
        /// </summary>
        /// <param name="pageInfo">页面实体信息</param>
        /// <param name="filter">查询条件</param>
        /// <returns></returns>
        [HttpGet]
        public JsonResult List(ArticleClassEntity filter, PageInfo pageInfo)
        {
            var result = articleClassService.GetListByFilter(filter, pageInfo);
            return Json(result);
        }
        public ActionResult Add()
        {
            return View();
        }
        [HttpPost]
        public ActionResult Add(ArticleClassEntity model)
        {
            model.CreateOn = DateTime.Now;
            var result = articleClassService.CreateEntity(model) ? SuccessTip() : ErrorTip();
            return Json(result);
        }
        public ActionResult Detail(int Id)
        {
            var model = articleClassService.ReadEntity(Id);
            return View(model);
        }
        public ActionResult Edit(int Id)
        {
            var model = articleClassService.ReadEntity(Id);
            return View(model);
        }
        [HttpPost]
        public ActionResult Edit(ArticleClassEntity model)
        {
            var result = articleClassService.UpdateEntity(model) ? SuccessTip() : ErrorTip();
            return Json(result);
        }
        [HttpPost]
        public ActionResult Delete(int Id)
        {
            //删除文章分类，同时删除分类下的文章
            var result = articleClassService.DeleteClassAllByClassId(Id) ? SuccessTip() : ErrorTip();
            return Json(result);
        }
    }
}